//
//  RegiestC.m
//  UniverseProject
//
//  Created by king on 2019/9/3.
//  Copyright © 2019年 Cloud2209. All rights reserved.
//


typedef enum : NSUInteger {
    TextFieldStyleSheetFiled = 0,
    TextFieldStyleSheetButton,
    TextFieldStyleSheetText,
} TextFieldStyleSheet;


#import "SGEasyButton.h"
#import "RegiestC.h"

@interface RegiestC ()

@property (nonatomic, weak)UIButton *confirmBtn;
@property (nonatomic, weak)UIButton *code_Btn;
@property (nonatomic, weak)UIScrollView *scrollView;

@end

@implementation RegiestC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.inviter_name = @"蔡徐坤(推广大使)";
    
    self.navigationItem.title = @"注册";
    
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    scrollView.backgroundColor = LGCOLOR(@"#F5F5F5");
    scrollView.contentSize = CGSizeMake(self.view.frame.size.width, 800);
    [self.view addSubview:scrollView];
    self.scrollView = scrollView;
    
    UIView *headerBox1 = [self headerBoxWithFrame:CGRectMake(0, 0, K_SCREEN_WIDTH, 50) Title:@"注册信息" RightTitle:nil];
    
    UITextField *nameTF = [self TFBoxWithFrame:CGRectMake(0, headerBox1.bottom, K_SCREEN_WIDTH, 50) Title:@"姓名" HolderText:@"请输入" StyleSheetType:TextFieldStyleSheetFiled IsRequire:YES];
    
    UITextField *phontTF = [self TFBoxWithFrame:CGRectMake(0, nameTF.superview.bottom + 1, K_SCREEN_WIDTH, 50) Title:@"手机号" HolderText:@"请输入" StyleSheetType:TextFieldStyleSheetFiled IsRequire:YES];

    UITextField *codeTF = [self TFBoxWithFrame:CGRectMake(0, phontTF.superview.bottom + 1, K_SCREEN_WIDTH, 50) Title:@"验证码" HolderText:@"请输入" StyleSheetType:TextFieldStyleSheetButton IsRequire:YES];
    
    UITextField *bindTF = [self TFBoxWithFrame:CGRectMake(0, codeTF.superview.bottom + 1, K_SCREEN_WIDTH, 50) Title:@"绑定上级" HolderText:@"" StyleSheetType:TextFieldStyleSheetText IsRequire:YES];
    
    UIView *headerBox2 = [self headerBoxWithFrame:CGRectMake(0, bindTF.superview.bottom, K_SCREEN_WIDTH, 50) Title:@"人事信息" RightTitle:@"以下信息涉及到工资发放，请如实填写"];
    
    UITextField *sfzTF = [self TFBoxWithFrame:CGRectMake(0, headerBox2.bottom, K_SCREEN_WIDTH, 50) Title:@"身份证" HolderText:@"请输入" StyleSheetType:TextFieldStyleSheetFiled IsRequire:YES];
    
    UITextField *khhTF = [self TFBoxWithFrame:CGRectMake(0, sfzTF.superview.bottom + 1, K_SCREEN_WIDTH, 50) Title:@"开户行" HolderText:@"请输入" StyleSheetType:TextFieldStyleSheetFiled IsRequire:YES];
    
    UITextField *yhkhTF = [self TFBoxWithFrame:CGRectMake(0, khhTF.superview.bottom + 1, K_SCREEN_WIDTH, 50) Title:@"银行卡号" HolderText:@"请输入" StyleSheetType:TextFieldStyleSheetFiled IsRequire:YES];
    
    CGFloat padding = 42;
    CGFloat maxW = K_SCREEN_WIDTH - padding * 2;
    UIButton *confirmBtn = [UIButton defaultBtnWithFrame:CGRectMake(padding, K_SCREEN_HEIGHT - k_SafeAreaTopHeight - 15 - 49, maxW, 49) Title:@"确认" target:self action:@selector(confirmClick:)];
    [self.view addSubview:confirmBtn];
    self.confirmBtn = confirmBtn;
}



- (UIView *)headerBoxWithFrame:(CGRect)frame
                         Title:(NSString *)title
                    RightTitle:(NSString *)rightTitle
{
    CGFloat padding = 15;
    CGFloat maxW = K_SCREEN_WIDTH - padding * 2;
    
    UIView *boxView = [[UIView alloc] initWithFrame:frame];
    boxView.backgroundColor = LGCOLOR(@"#F5F5F5");
    [self.scrollView addSubview:boxView];
    
    UILabel *titleLab = [UILabel labelWithTitle:@"" color:LGCOLOR(@"#333333") font:LGFONT(15)];
    titleLab.frame = CGRectMake(padding, 0, maxW, 50);
    [boxView addSubview:titleLab];
    
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"注册信息" attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang SC" size: 16],NSForegroundColorAttributeName: [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0]}];
    titleLab.attributedText = string;
    
    if (rightTitle) {
        UILabel *detailLab = [UILabel labelWithTitle:@"" color:LGCOLOR(@"#333333") font:LGFONT(15)];
        detailLab.frame = CGRectMake(padding, 0, maxW, 50);
        detailLab.textAlignment = 2;
        [boxView addSubview:detailLab];
        
        NSMutableAttributedString *string1 = [[NSMutableAttributedString alloc] initWithString:rightTitle attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang SC" size: 12],NSForegroundColorAttributeName: [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0]}];
        detailLab.attributedText = string1;
    }
    
    return boxView;
}



- (UITextField *)TFBoxWithFrame:(CGRect)frame
                          Title:(NSString *)title
                     HolderText:(NSString *)holderText
                 StyleSheetType:(NSInteger)styleSheetType
                      IsRequire:(BOOL)isRequire{
    
    CGFloat padding = 15;
    CGFloat maxW = K_SCREEN_WIDTH - padding * 2;
    
    UIView *boxView = [[UIView alloc] initWithFrame:frame];
    boxView.backgroundColor = LGCOLOR(@"ffffff");
    [self.scrollView addSubview:boxView];
    
    UITextField *textField = [UITextField new];
    textField.frame = CGRectMake(padding, 0, maxW, 50);
    textField.textAlignment = 2;
    UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
    UILabel *leftViewLab = [UILabel labelWithTitle:@"" color:LGCOLOR(@"#333333") font:LGFONT(15)];
    leftViewLab.frame = CGRectMake(0, 0, 100, 50);
    [leftView addSubview:leftViewLab];
    textField.leftView = leftView;
    textField.leftViewMode = UITextFieldViewModeAlways;
    textField.placeholder = holderText;
    // 输入文字颜色
    textField.textColor = LGCOLOR(@"#333333");
    // 设置搜索框placeholder文字颜色
//    [textField setValue:LGCOLOR(@"#CCCCCC") forKeyPath:@"_placeholderLabel.textColor"];
    textField.font = [UIFont systemFontOfSize:15];
    [boxView addSubview:textField];
    
    if (isRequire) {
        NSString *str = [NSString stringWithFormat:@"* %@",title];
        NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:str attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang SC" size: 15]}];
        [string addAttribute:NSForegroundColorAttributeName value:LGCOLOR(@"#EC142D") range:NSMakeRange(0, 1)];
        leftViewLab.attributedText = string;
    }else{
        leftViewLab.text = title;
    }
    
    switch (styleSheetType) {
        case TextFieldStyleSheetButton:{
            UIView *rightBoxView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
            UIButton *code_Btn = [UIButton buttonWithTitle:@"发送验证码" titleColor:LGCOLOR(@"#FFFFFF") font:LGFONT(12) target:self action:@selector(code_Btn_Click:)];
            code_Btn.backgroundColor = LGCOLOR(@"#F33C51");
            code_Btn.frame = CGRectMake(20, 11, 80, 28);
            code_Btn.cornerRadius = 4;
            [rightBoxView addSubview:code_Btn];
            textField.rightView = rightBoxView;
            textField.rightViewMode = UITextFieldViewModeAlways;
            self.code_Btn = code_Btn;
        }
            
            break;
        case TextFieldStyleSheetText:{
            textField.text = self.inviter_name?:@"";
            textField.userInteractionEnabled = NO;
        }
            break;
            
        default:
            break;
    }
    
    return textField;
}

- (void)code_Btn_Click:(UIButton *)btn{
    
//    [MBProgressHUD showLoading];
//    [User sendCodeWithType:@"0" Phone:self.regisPhoneT.text ActionSuccess:^(NSString *key) {
//        [MBProgressHUD hideHud];
//        [MBProgressHUD showMessage:@"验证码已发送!"];
//        [btn setTitleColor:LGCOLOR(@"#BEBEBE") forState:UIControlStateNormal];
//        [btn SG_countdownWithSecond:60 completion:^{
//            [btn setTitle:@"获取验证码" forState:UIControlStateNormal];
//            [btn setTitleColor:LGCOLOR(@"#24242D") forState:UIControlStateNormal];
//        }];
//    } fail:nil];
}

- (void)confirmClick:(UIButton *)btn{
    
    
}



@end
